def is_prime(num):
    if num < 2:
        return False
    for i in range(2, int(num**0.5) + 1):
        if num % i == 0:
            return False
    return True

def closest_prime(y):
    offset = 0
    while True:
        if is_prime(y + offset):
            return y + offset
        elif is_prime(y - offset):
            return y - offset
        offset += 1

t = {
    'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4,
    'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9
}

try:
    input_words = input().split()
    if len(input_words) != 3:
        raise ValueError
    y = int(''.join(str(t[word]) for word in input_words))
    print(closest_prime(y))
except (KeyError, ValueError):
    print("Wrong input")